from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import DBUtils
import Buy


class TestBuy:

    def test_buy1(self):

        Buy.buy1('lisi','123456',2,1,'666666','买入成功!','test_buy1')

    def test_buy2(self):

        Buy.buy1('lisi', '123456', 2, 1, '666667', '买入失败!', 'test_buy2')


    def test_buy3(self):

        Buy.buy1('lisi4', '123456', 2, 1, '666666', '买入失败!，银行卡余额不足', 'test_buy3')


    def test_buy4(self):

        Buy.buy1('lisi5','123456',2,1,'666666','买入失败!，请绑定银行卡','test_buy4')


    def test_buy5(self):

        driver = Buy.buy2('lisi', '123456', 2, 2, '666666')
        result = driver.find_element(By.XPATH, '//div[@class="jconfirm-content"]/div').text

        sql = 'select balance from bankcard where userId = 1 and defaultl = 1'
        data = DBUtils.select(sql,[])

        if result == '买入成功!' and data[0][0] == 999900.00:
            print('通过')
        else:
            print('不通过！')
            driver.save_screenshot('test_buy5.png')

        assert result == '买入成功!' and data[0][0] == 999900.00

        driver.quit()


    def test_buy6(self):
        # 买入失败
        Buy.buy1('lisi', '123456', 2, 2, '666667', '买入失败!', 'test_buy6')


    def test_buy7(self):

        Buy.buy1('lisi4', '123456', 2, 2, '666666', '买入失败!，银行卡余额不足', 'test_buy7')



    def test_buy8(self):

        Buy.buy1('lisi5', '123456', 2, 2, '666666', '买入失败!，请绑定银行卡', 'test_buy8')



    def test_buy9(self):
        driver = Buy.buy2('lisi', '123456', 2, 3, '666666')

        result = driver.find_element(By.XPATH, '//div[@class="jconfirm-content"]/div').text

        sql = 'select balance from bankcard where userId = 1 and defaultl = 1'
        data = DBUtils.select(sql,[])

        if result == '买入成功!' and data[0][0] == 999900.00:
            print('通过')
        else:
            print('不通过！')
            driver.save_screenshot('test_buy9.png')

        assert result == '买入成功!' and data[0][0] == 999900.00

        driver.quit()


    def test_buy10(self):

        Buy.buy1('lisi', '123456', 2, 3, '666667', '买入失败!', 'test_buy10')



    def test_buy11(self):

        Buy.buy1('lisi4', '123456', 2, 3, '666666', '买入失败!，银行卡余额不足', 'test_buy11')



    def test_buy12(self):

        Buy.buy1('lisi5', '123456', 2, 3, '666666', '买入失败!，请绑定银行卡', 'test_buy12')



    def test_buy13(self):

        Buy.buy1('lisi6', '123456', 2, 3, '666667', '买入失败!,请前往个人信息设置支付密码', 'test_buy13')


    def test_buy14(self):

        driver = Buy.buy2('lisi7', '123456', 2, 3, '666666')

        result = driver.find_element(By.XPATH, '//div[@class="jconfirm-content"]/div').text

        sql = 'select balance from bankcard where userId = 83 and defaultl = 1'
        data = DBUtils.select(sql, [])

        if result == '买入成功!' and data[0][0] == 7000.00:
            print('通过')
        else:
            print('不通过！')

        assert result == '买入成功!' and data[0][0] == 7000.00

        driver.quit()


    def test_buy15(self):
        driver = Buy.buy2('lisi7', '123456', 2, 3, '666666')

        result = driver.find_element(By.XPATH, '//div[@class="jconfirm-content"]/div').text

        sql = 'select balance from bankcard where userId = 83 and defaultl = 1'
        data = DBUtils.select(sql, [])

        if result == '买入成功!' and data[0][0] == 7000.00:
            print('通过')
        else:
            print('不通过！')

        assert result == '买入成功!' and data[0][0] == 7000.00

        driver.quit()


    def test_buy16(self):

        Buy.buy1('lisi5', '123456', 2, 3, '666666', '买入失败!，请绑定银行卡', 'test_buy12')
